home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 6020 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  1.0 KB

  1. Path: news1.h1.usa.pipeline.com!usenet
  2. From: grantp@usa.pipeline.com(Pete)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Mod or if?
  5. Date: 11 Feb 1996 11:47:24 GMT
  6. Organization: Kalevi, Inc.
  7. Message-ID: <4fkl0c$nrt@news1.usa.pipeline.com>
  8. NNTP-Posting-Host: pipe10.h1.usa.pipeline.com
  9. X-PipeUser: grantp
  10. X-PipeHub: usa.pipeline.com
  11. X-PipeGCOS: (Pete)
  12. X-Newsreader: Pipeline USA v3.3.0
  13.  
  14. On Feb 09, 1996 18:25:58 in article <Mod or if?>, 'weikel@rohan.sdsu.edu
  15. (weikel)' wrote: 
  16.  
  17.  
  18. >Which is better? 
  19. >x = (x mod 7); 
  20. What's mod?  Maybe you mean x = x % 7;  or its abbreviation 
  21. x %= 7;  (Not quite the same as modulus since in C/C++ we 
  22. have only the remainder operator) 
  23.  
  24. >or 
  25. >if (x == 7) x = 0;  
  26. >in terms of performance?  I know that the mod function is slow 
  27. >,but the if method seems brute-forceish. 
  28. The if method is much faster -- mostly because it doesn't 
  29. give the same result. 
  30.  
  31. BTW, worrying about the performance of built-in operators is 
  32. usually a waste of time. 
  33.  
  34. -- 
  35. Pete Grant 
  36. Kalevi, Inc. 
  37. Object Oriented Software Development
  38.